package com.rpj.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.rpj.entity.Book;
import com.rpj.entity.BookDto;
import com.rpj.entity.StuDto;
import com.rpj.entity.StuEntity;
import com.rpj.service.BookService;

@RestController
public class BookController {
@Autowired
BookService bookservice;
@RequestMapping("/bookquery")
public Object bookQuery(BookDto dto,int page,int limit) {
	Pageable pageable = PageRequest.of(page-1, limit);
	Page<Book> pagebook = bookservice.queryByCondition(dto, pageable);
	HashMap<String, Object> map = new HashMap<String, Object>();
	map.put("code", 0);
	map.put("msg", "");
	map.put("count",pagebook.getTotalElements() );
	map.put("data", pagebook.getContent());
	return map;
}
@RequestMapping(value="/bookupdate",method = RequestMethod.POST)
public Object bookupdate(String bookname,String bookauthor,String bookpress,String booknum,String bookcate,String bookmessage,String bookprice,String bookaddress,String onlinenum,String borrownum,String bookid){
int i = bookservice.updateBook(bookname, bookauthor, bookpress, booknum, bookcate, bookmessage, bookprice, bookaddress, onlinenum, borrownum, bookid);
if(i>0) {
	return true;
}else {
	return false;
}
}
@RequestMapping(value="/booksave",method = RequestMethod.POST)
public Object booksave(Book b) {
	Book save = bookservice.save(b);
	if(save!=null) {
		return true;
	}else {
		return false;
	}
}
@RequestMapping(value="/bookpress",method = RequestMethod.POST)
public Object bookpress() {
	List<String> list = bookservice.bookpress();
	return list;
}

}